﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class main3 : System.Web.UI.Page
{
    string strconn = ConfigurationManager.ConnectionStrings["a123"].ToString();
    SqlConnection sqlconn;
    string sqlstr;
    protected void Page_Load(object sender, EventArgs e)
    {
        string text = Request.QueryString["var"];
        string aa = Request.QueryString["id"];
        if (!IsPostBack)
        {
            int a = Convert.ToInt32(text);
            int b = Convert.ToInt32(aa);
            if (a == 99)
            {
                
                binc(b);
            }
            else
            {
                bind(a);
            }
        }
    }
    public void bind(int classid)
    {
        sqlconn = new SqlConnection(strconn);
        sqlconn.Open();
        string sqlstr = "select * from tb_BookInfo where ClassID='" + classid + "'";
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn);
        DataSet myds = new DataSet();
        myda.Fill(myds, "BookID");

        GridView2.DataSource = myds;
        GridView2.DataKeyNames = new string[] { "BookID" };
        GridView2.DataBind();

        sqlconn.Close();
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)GridView2.Rows[i].FindControl("Label2");
            System.Web.UI.WebControls.HyperLink hyperlink1 = (System.Web.UI.WebControls.HyperLink)GridView2.Rows[i].FindControl("HyperLink5");
            //string number = GridView1.Rows[0].Cells[1].Text;
            hyperlink1.NavigateUrl = "~/main1.aspx?id=" + GridView2.DataKeys[i].Value;
        }
    }
    public void binc(int classid)
    {
        
        sqlconn = new SqlConnection(strconn);
        sqlconn.Open(); 
        //sqlstr = "select * from tb_BookInfo where Recommend='true'";
        if (classid == 2)
        {
            sqlstr = "select * from tb_BookInfo where Recommend='true'";
        }
        else if (classid == 3)
        {
            sqlstr = "select * from tb_BookInfo where Discount='true'";
        }
        else if (classid == 4)
        {
            sqlstr = "select * from tb_BookInfo where Sell_well='true'";
        }
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn);
        DataSet myds = new DataSet();
        myda.Fill(myds, "BookID");

        GridView2.DataSource = myds;
        GridView2.DataKeyNames = new string[] { "BookID" };
        GridView2.DataBind();

        sqlconn.Close();
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)GridView2.Rows[i].FindControl("Label2");
            System.Web.UI.WebControls.HyperLink hyperlink1 = (System.Web.UI.WebControls.HyperLink)GridView2.Rows[i].FindControl("HyperLink5");
            //string number = GridView1.Rows[0].Cells[1].Text;
            hyperlink1.NavigateUrl = "~/main1.aspx?id=" + GridView2.DataKeys[i].Value;
        }
    }
       
}